package net.csdra.DongPoShuZiTuShuGuan.service;

import net.csdra.DongPoShuZiTuShuGuan.domain.ExternalLink;
import net.csdra.DongPoShuZiTuShuGuan.domain.ExternalLinkRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/**
 * Created by add on 2018/1/17.
 */
@Service
public class ExternalLinkServiceImpl implements ExternalLinkService {
    @Autowired
    ExternalLinkRepository externalLinkRepository;
    @Override
    public Page<ExternalLink> getExternalLinkByMetaId(GetExternalLinkByMetaId getExternalLinkByMetaId) {
        Assert.notNull(getExternalLinkByMetaId, "参数不能为空");
        Assert.hasText(getExternalLinkByMetaId.getMetaId(), "metaId不能为空");
        //根目录按钮metaId为ROOT
        Page<ExternalLink> page = this.externalLinkRepository.findByMetaId(getExternalLinkByMetaId.getMetaId(),
                new PageRequest(getExternalLinkByMetaId.getPage(), getExternalLinkByMetaId.getSize(), Sort.Direction.ASC, "viewOrder"));
        return page;
    }
}
